package ca.ericslandry.client.mvp.validation;

import com.google.gwt.user.client.ui.HasValue;

public class PostalCodeValidator implements Validator {
	private HasValue<String> postalCode;

	public PostalCodeValidator(HasValue<String> postalCode) {
		this.postalCode = postalCode;
	}

	@Override
	public boolean validate() {
		String value = postalCode.getValue();
		value = value.toUpperCase().replaceAll("\\s", "");
		return value.matches("^([A-Z]\\d[A-Z]\\d[A-Z]\\d)$");
	}

	public HasValue<String> getPostalCode() {
		return postalCode;
	}

	public void setPostalCode(HasValue<String> postalCode) {
		this.postalCode = postalCode;
	}
}
